export function throttle(f, delay = 500, immediate = true) {
  let waiting = false,
    args
  return function (...rest) {
    args = rest
    if (!waiting) {
      waiting = true
      immediate && f.apply(this, args)
      setTimeout(() => {
        waiting = false
        !immediate && f.apply(this, args)
      }, delay)
    }
  }
}
